package com.jt.tenant.activity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.jt.tenant.R;
import com.jt.tenant.adapter.ReportAdapter;
import com.jt.tenant.conn.GetReportList;
import com.zcx.helper.http.AsyCallBack;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/2/14.
 */
public class DiagnosisActivity extends JTActivity implements View.OnClickListener {
    private TextView title_name;

    private List<GetReportList.Info> list1 = new ArrayList<>();

    private ListView listView;

    private ReportAdapter adapter;

    private LinearLayout mLineYes, mLineNo;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_diagnosis);

        initView();

        GetList();

    }

    private void initView() {

        (title_name = (TextView) findViewById(R.id.tv_title_name)).setText("诊断报告");

        listView = (ListView) findViewById(R.id.diagnosis_list_view);

        mLineYes = (LinearLayout) findViewById(R.id.lin_diagnosis_yes);

        mLineNo = (LinearLayout) findViewById(R.id.lin_diagnosis_no);

        adapter = new ReportAdapter(this, list1);

        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

                Intent intent = new Intent(DiagnosisActivity.this,DiagnosticReportActivity.class);
                Bundle bundle = new Bundle();
                bundle.putString("id",list1.get(position).id);
                bundle.putString("score",list1.get(position).score);
                bundle.putString("scoreDate",list1.get(position).scoreDate);
                bundle.putString("state",list1.get(position).sh);
                intent.putExtras(bundle);
                startActivity(intent);

            }

        });

    }

    private void GetList() {

        new GetReportList(new AsyCallBack<List<GetReportList.Info>>() {

            @Override
            public void onSuccess(String toast, int type, List<GetReportList.Info> list) throws Exception {

                list1.addAll(list);

                if (toast.equals("000")) {

                    mLineNo.setVisibility(View.VISIBLE);

                    adapter.notifyDataSetChanged();

                } else {

                    mLineYes.setVisibility(View.VISIBLE);

                    Toast.makeText(DiagnosisActivity.this, toast, Toast.LENGTH_SHORT).show();

                }

            }
        }).execute(DiagnosisActivity.this);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {

        }

    }


}
